 // nav导航区的创建
 var head=document.querySelector("#head");
 var nav=document.querySelector("#nav");
 let xhr1=new XMLHttpRequest();
 xhr1.open("get","http://chst.vip:1234/api/getindexmenu",false);
 xhr1.onload=function(){
     let lis1="";
     if(xhr1.status===200){
         let res1=JSON.parse(xhr1.responseText);
         console.log(res1.result);
         res1.result.forEach(item => {
                    lis1+=`
                    <div id="small" >
                    <a href="./html/${item.titlehref}">
                     <span>
                    ${item.img}
                    </span>
                    </a>
                    <p>${item.name}</p>
                    </div>  
                     
             `     
         });
     }
     nav.innerHTML=lis1
 }
 xhr1.send();

//  更多抽屉收放 a标签href=#
  let imgs1=document.querySelectorAll(" #small img");
 let navbox=document.querySelector("#nav")
 var smallbox=document.querySelector("#small")
/*  imgs1[7].onclick=function(){
    console.log("111");
 } */

let flag=false;
 $("#small img").eq(7).click(function(){
/*     if(flag){
        navbox.style.height="2.6rem";
    }else{
        navbox.style.height="1.67rem";
        navbox.style.overflow="hidden";
    }
    flag=!flag;
    console.log(this.parent.parent); */
    $(this).parent().parent().attr("href","#");
    // $(this).parent().parent().attr("href","javascript:;")
 }) 

// 2.
 $("#nav #small").eq(7).find("a").prop("href","#").parent().click(function(){
    $(this).nextAll().slideToggle();
 })

// slideDown()    高度展开    自带动画效果
// slideUp()      高度收起    自带动画效果
// slideToggle    展开收起自动切换
    

//  产品列表
let product=document.querySelector("#product")
let xhr2=new XMLHttpRequest();
 xhr2.open("get","http://chst.vip:1234/api/getmoneyctrl",false);
 xhr2.onload=function(){
    let lis2="";
    if(xhr2.status===200){
        let res2=JSON.parse(xhr2.responseText); 
        console.log(res2.result);
        let regExp = /(?<=imgurl=)[^'"]*/;
        res2.result.forEach(items => {
            console.log(items);
            let imgsrc=items.productImg2.match(regExp)[0];
            lis2 +=`
            <ul class="ulboxs">
                <li id="${items.productId}">
            <div class="left">
            <img src="${imgsrc}" alt="">
            </div>

            <div class="right">
                <div class="top">
                    ${items.productName}
                    <span>${items.productPinkage}</span>
                </div>
                <div class="bot">
                    <span class="sp1">${items.productFrom}|${items.productTime}</span>
                    <em>
                        <i class="iconfont icon-xiaoxixinxihuihuahuida"></i>
                        <span>${items.productComCount}</span>
                    </em>
                </div>
            </div>
                </li>
            </ul>
            `
        })
    }
    product.innerHTML=lis2
    }
 xhr2.send();

//  回到顶部
let totop=document.querySelector(".content");
totop.onclick=function(){
    $("body,html").animate({scrollTop:0}, 1000)
}


// 产品页跳转
$(".ulboxs").click(function(){
    // console.log($(this).find("li").prop("id"));
    window.location.href=`./html/savedetail.html?productid=${+$(this).find("li").prop("id")}`
})


    

 
